/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package apprentissagejava;

import com.mysql.jdbc.Connection;
import java.awt.Color;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author tordeepweb
 */
public class Access_data_base extends javax.swing.JFrame {

    Connection connexion;

    /**
     * Creates new form Access_data_base
     */
    public Access_data_base() {
        initComponents();
        this.connexion = null;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPaneAccesBDD = new javax.swing.JTabbedPane();
        jPanelConnexion = new javax.swing.JPanel();
        jTextFieldUtilisateurBDD = new javax.swing.JTextField();
        jButtonSeConnecter = new javax.swing.JButton();
        jLabelEtat = new javax.swing.JLabel();
        jLabelDAO = new javax.swing.JLabel();
        jButtonTest = new javax.swing.JButton();
        jLabelAdresse = new javax.swing.JLabel();
        jTextFieldAdresse = new javax.swing.JTextField();
        jLabelPort = new javax.swing.JLabel();
        jTextFieldPort = new javax.swing.JTextField();
        jLabelNonBDD = new javax.swing.JLabel();
        jTextFieldNomBDD = new javax.swing.JTextField();
        jLabelMBPBDD = new javax.swing.JLabel();
        jTextFieldMBPBDD = new javax.swing.JTextField();
        jLabelUtilisateurBDD = new javax.swing.JLabel();
        jPanelGestionBDD = new javax.swing.JPanel();
        jButtonCreerTable = new javax.swing.JButton();
        jTextFieldNomTableACreer = new javax.swing.JTextField();
        jLabelEtatCreation = new javax.swing.JLabel();
        jButtonSupprimerTable = new javax.swing.JButton();
        jTextFieldTableASupprimer = new javax.swing.JTextField();
        jLabelEtatSuppression = new javax.swing.JLabel();
        jButtonViderTable = new javax.swing.JButton();
        jTextFieldNomTableAVider = new javax.swing.JTextField();
        jLabelEtatVider = new javax.swing.JLabel();
        jLabelOutilBDD = new javax.swing.JLabel();
        jPanelCrud = new javax.swing.JPanel();
        jLabelID = new javax.swing.JLabel();
        jTextFieldID = new javax.swing.JTextField();
        jLabelNom = new javax.swing.JLabel();
        jTextFieldNom = new javax.swing.JTextField();
        jButtonAfficher = new javax.swing.JButton();
        jButtonCreer = new javax.swing.JButton();
        jButtonModifier = new javax.swing.JButton();
        jButtonSupprimer = new javax.swing.JButton();
        jTextFieldResultat = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButtonSeConnecter.setText("Se connecter");
        jButtonSeConnecter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSeConnecterActionPerformed(evt);
            }
        });

        jLabelEtat.setText("                             Non connecté");

        jLabelDAO.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        jLabelDAO.setText("DAO: DATA ACCESS OBJECT WITH JDBC FOR JAVA ");

        jButtonTest.setText("TEST");
        jButtonTest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTestActionPerformed(evt);
            }
        });

        jLabelAdresse.setText("Adresse du serveur BDD");

        jTextFieldAdresse.setText("localhost");

        jLabelPort.setText("Port (éventuel)");

        jTextFieldPort.setText("3306");

        jLabelNonBDD.setText("Nom de la BDD");

        jLabelMBPBDD.setText("Mot de passe BDD");

        jTextFieldMBPBDD.setText("localhost");

        jLabelUtilisateurBDD.setText("Utilisateur BDD");

        javax.swing.GroupLayout jPanelConnexionLayout = new javax.swing.GroupLayout(jPanelConnexion);
        jPanelConnexion.setLayout(jPanelConnexionLayout);
        jPanelConnexionLayout.setHorizontalGroup(
            jPanelConnexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelConnexionLayout.createSequentialGroup()
                .addContainerGap(90, Short.MAX_VALUE)
                .addGroup(jPanelConnexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelConnexionLayout.createSequentialGroup()
                        .addComponent(jLabelDAO, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelConnexionLayout.createSequentialGroup()
                        .addComponent(jButtonTest, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelConnexionLayout.createSequentialGroup()
                        .addGroup(jPanelConnexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabelMBPBDD, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabelNonBDD, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabelPort, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabelAdresse, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabelUtilisateurBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(101, 101, 101)
                        .addGroup(jPanelConnexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldPort, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldNomBDD, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldMBPBDD, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldUtilisateurBDD, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldAdresse, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(76, 76, 76))
            .addGroup(jPanelConnexionLayout.createSequentialGroup()
                .addGroup(jPanelConnexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelConnexionLayout.createSequentialGroup()
                        .addGap(173, 173, 173)
                        .addComponent(jButtonSeConnecter, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelConnexionLayout.createSequentialGroup()
                        .addGap(116, 116, 116)
                        .addComponent(jLabelEtat, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelConnexionLayout.setVerticalGroup(
            jPanelConnexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelConnexionLayout.createSequentialGroup()
                .addContainerGap(47, Short.MAX_VALUE)
                .addComponent(jLabelDAO, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanelConnexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelConnexionLayout.createSequentialGroup()
                        .addComponent(jTextFieldAdresse, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jTextFieldPort, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(33, 33, 33)
                        .addComponent(jTextFieldNomBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(jTextFieldMBPBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(jTextFieldUtilisateurBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelConnexionLayout.createSequentialGroup()
                        .addComponent(jLabelAdresse, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31)
                        .addComponent(jLabelPort, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34)
                        .addComponent(jLabelNonBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(jLabelMBPBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29)
                        .addComponent(jLabelUtilisateurBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jButtonSeConnecter, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelEtat, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(jButtonTest)
                .addGap(43, 43, 43))
        );

        jTabbedPaneAccesBDD.addTab("Connexion", jPanelConnexion);

        jButtonCreerTable.setText("Créer la table");
        jButtonCreerTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreerTableActionPerformed(evt);
            }
        });

        jTextFieldNomTableACreer.setText("Table_exemple");

        jLabelEtatCreation.setText("...");

        jButtonSupprimerTable.setText("Supprimer la table");
        jButtonSupprimerTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSupprimerTableActionPerformed(evt);
            }
        });

        jTextFieldTableASupprimer.setText("Table_exemple");

        jLabelEtatSuppression.setText("...");

        jButtonViderTable.setText("Vider la table");
        jButtonViderTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonViderTableActionPerformed(evt);
            }
        });

        jTextFieldNomTableAVider.setText("Table_exemple");

        jLabelEtatVider.setText("...");

        jLabelOutilBDD.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        jLabelOutilBDD.setText("                    OUTILS BASE DE DONNEES");

        javax.swing.GroupLayout jPanelGestionBDDLayout = new javax.swing.GroupLayout(jPanelGestionBDD);
        jPanelGestionBDD.setLayout(jPanelGestionBDDLayout);
        jPanelGestionBDDLayout.setHorizontalGroup(
            jPanelGestionBDDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelGestionBDDLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelGestionBDDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonCreerTable, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSupprimerTable, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonViderTable, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 150, Short.MAX_VALUE)
                .addGroup(jPanelGestionBDDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabelEtatSuppression, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextFieldNomTableACreer, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldTableASupprimer, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .addComponent(jLabelEtatCreation, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEtatVider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextFieldNomTableAVider, javax.swing.GroupLayout.Alignment.TRAILING)))
            .addGroup(jPanelGestionBDDLayout.createSequentialGroup()
                .addGap(111, 111, 111)
                .addComponent(jLabelOutilBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanelGestionBDDLayout.setVerticalGroup(
            jPanelGestionBDDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelGestionBDDLayout.createSequentialGroup()
                .addGap(75, 75, 75)
                .addComponent(jLabelOutilBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64)
                .addGroup(jPanelGestionBDDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldNomTableACreer, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCreerTable, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addComponent(jLabelEtatCreation)
                .addGap(18, 18, 18)
                .addGroup(jPanelGestionBDDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldTableASupprimer, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSupprimerTable, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabelEtatSuppression)
                .addGap(9, 9, 9)
                .addGroup(jPanelGestionBDDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonViderTable, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNomTableAVider, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelEtatVider)
                .addContainerGap(199, Short.MAX_VALUE))
        );

        jTabbedPaneAccesBDD.addTab("Outils BDD", jPanelGestionBDD);

        jLabelID.setText("ID");

        jLabelNom.setText("Nom");

        jButtonAfficher.setText("Afficher le client dont l'ID est choisi");
        jButtonAfficher.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAfficherActionPerformed(evt);
            }
        });

        jButtonCreer.setText("Créer le client dont le nom est saisi");
        jButtonCreer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreerActionPerformed(evt);
            }
        });

        jButtonModifier.setText("Modifier le client dont l'ID est saisi");
        jButtonModifier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonModifierActionPerformed(evt);
            }
        });

        jButtonSupprimer.setText("Supprimer le client dont l'ID est saisi");
        jButtonSupprimer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSupprimerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelCrudLayout = new javax.swing.GroupLayout(jPanelCrud);
        jPanelCrud.setLayout(jPanelCrudLayout);
        jPanelCrudLayout.setHorizontalGroup(
            jPanelCrudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCrudLayout.createSequentialGroup()
                .addGroup(jPanelCrudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelCrudLayout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(jLabelID, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(59, 59, 59))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelCrudLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabelNom, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)))
                .addGroup(jPanelCrudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldID, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                    .addComponent(jTextFieldNom))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelCrudLayout.createSequentialGroup()
                .addGap(0, 120, Short.MAX_VALUE)
                .addGroup(jPanelCrudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelCrudLayout.createSequentialGroup()
                        .addGroup(jPanelCrudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonAfficher, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonCreer, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonModifier, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonSupprimer, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                        .addGap(150, 150, 150))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelCrudLayout.createSequentialGroup()
                        .addComponent(jTextFieldResultat, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(89, 89, 89))))
        );
        jPanelCrudLayout.setVerticalGroup(
            jPanelCrudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCrudLayout.createSequentialGroup()
                .addGap(92, 92, 92)
                .addGroup(jPanelCrudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelID)
                    .addComponent(jTextFieldID, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(42, 42, 42)
                .addGroup(jPanelCrudLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNom, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNom, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(46, 46, 46)
                .addComponent(jButtonAfficher)
                .addGap(11, 11, 11)
                .addComponent(jButtonCreer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonModifier)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonSupprimer)
                .addGap(36, 36, 36)
                .addComponent(jTextFieldResultat, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                .addGap(32, 32, 32))
        );

        jTabbedPaneAccesBDD.addTab("CRUD", jPanelCrud);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jTabbedPaneAccesBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 539, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(40, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPaneAccesBDD, javax.swing.GroupLayout.PREFERRED_SIZE, 616, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(41, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonSeConnecterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSeConnecterActionPerformed
        // TODO add your handling code here:
        if (this.connexion == null) {
            try {

                String ChaineConnexion = "jdbc:mysql://" + jTextFieldAdresse.getText();

                if (jTextFieldPort.getText().equals("")) {
                    ChaineConnexion += "." + jTextFieldPort.getText();
                }
                ChaineConnexion += "/" + jTextFieldNomBDD.getText();

                this.connexion = (Connection) DriverManager.getConnection(ChaineConnexion, jTextFieldUtilisateurBDD.getText(), jTextFieldMBPBDD.getText());

                if (this.connexion != null) {

                    jLabelEtat.setText("La connexion est desormais active");
                    jButtonSeConnecter.setText("Se déconnecter");

                } else {

                    jLabelEtat.setText("Non connecté");
                }
            } catch (SQLException ex) {
                jLabelEtat.setText("Erreur de connexion, vérifiez les données fournies");
                Logger.getLogger(Access_data_base.class.getName()).log(Level.SEVERE, null, ex);

            }
        }
            else {
            jLabelEtat.setText("Non connecté");
            jButtonSeConnecter.setText("Se connecter");
            jTextFieldAdresse.setText(" ");
            jTextFieldMBPBDD.setText(" ");
            jTextFieldNomBDD.setText(" ");
            jTextFieldUtilisateurBDD.setText(" ");
            jTextFieldPort.setText(" ");
            this.connexion=null;
        }


    }//GEN-LAST:event_jButtonSeConnecterActionPerformed

    private void jButtonTestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTestActionPerformed
        // TODO add your handling code here:
        jTextFieldAdresse.setText("192.168.29.10");
        jTextFieldMBPBDD.setText("Materobi");
        jTextFieldNomBDD.setText("speedymarketclass");
        jTextFieldUtilisateurBDD.setText("root");
    }//GEN-LAST:event_jButtonTestActionPerformed

    private void jButtonCreerTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreerTableActionPerformed
        // TODO add your handling code here:
        if(this.connexion != null){
         try {
             Statement maRequete = this.connexion.createStatement();
             String nomTable = jTextFieldNomTableACreer.getText();
             String requeteCreationTable = "create table " + nomTable;
             requeteCreationTable += "(id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, nom varchar(255) not null)";
             requeteCreationTable += "ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ";
             maRequete.executeUpdate(requeteCreationTable);
             jLabelEtatCreation.setText("Création de la table " + nomTable + " / OK !!");
             
             } catch (SQLException ex) {
                jLabelEtatCreation.setText("Erreur survenue lors de la création de la table");
                Logger.getLogger(Access_data_base.class.getName()).log(Level.SEVERE, null, ex);
             }  
        } else {
            jLabelEtatCreation.setText("La connexion n'est pas active...");
        
        }
    }//GEN-LAST:event_jButtonCreerTableActionPerformed

    private void jButtonSupprimerTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSupprimerTableActionPerformed
        // TODO add your handling code here:
        if(this.connexion != null){
        try {
             Statement maRequete = this.connexion.createStatement();
              String nomTable = jTextFieldTableASupprimer.getText();
              String requeteSupressionTable = "DROP table " + nomTable;
              maRequete.executeUpdate(requeteSupressionTable);
             jLabelEtatSuppression.setText("Supression de la table " + nomTable + " / OK !!");
          
             } catch (SQLException ex) {
             jLabelEtatSuppression.setText("Erreur survenue lors de la supression de la table");
             Logger.getLogger(Access_data_base.class.getName()).log(Level.SEVERE, null, ex);
             }  
        }else{
            jLabelEtatSuppression.setText("La connexion n'est pas active...");
        
        }
    }//GEN-LAST:event_jButtonSupprimerTableActionPerformed

    private void jButtonViderTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonViderTableActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jButtonViderTableActionPerformed

    private void jButtonAfficherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAfficherActionPerformed
        // TODO add your handling code here:
        if(this.connexion != null){
          if (!jTextFieldID.getText().equals("")){
          
              try {
                    Statement maRequete = this.connexion.createStatement();
                    ResultSet lesTuples = maRequete.executeQuery("select * from clients where code_client=" + jTextFieldID.getText());
                    
                if(lesTuples.next()) { 	   
                jTextFieldResultat.setForeground(Color.green);
                jTextFieldResultat.setText("Chargement réussi");
                jTextFieldNom.setText(lesTuples.getString("nom_client"));
                }
                else {
                    
                    jTextFieldResultat.setForeground(Color.red);
                    jTextFieldResultat.setText("Echec du chargement, la requête n'a pas rétourner d'informations");
                }
                    
          }catch (SQLException ex) {
                  
                 jTextFieldResultat.setForeground(Color.red);
                jTextFieldResultat.setText("Erreur, le champ ID n'est pas renseigné !!");  
                  Logger.getLogger(Access_data_base.class.getName()).log(Level.SEVERE, null, ex);
                  }     
          } else {
              jTextFieldResultat.setForeground(Color.red);
              jTextFieldResultat.setText("Erreur, le champ ID n'est pas renseigné !!");
                    
              
          }
            
        }   
    }//GEN-LAST:event_jButtonAfficherActionPerformed

    private void jButtonCreerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreerActionPerformed
        // TODO add your handling code here:
            if(this.connexion != null){
          if (!jTextFieldNom.getText().equals("")){
          
              try {
          Statement maRequete = this.connexion.createStatement();
          int nombreDeTuplesInseres= maRequete.executeUpdate("insert into clients values (null, '"+ jTextFieldNom.getText()  + "')");
	   
                jTextFieldResultat.setForeground(Color.green);
                jTextFieldResultat.setText("Chargement réussi");
  
          }catch (SQLException ex) {
                  
                 jTextFieldResultat.setForeground(Color.red);
                jTextFieldResultat.setText("Echec du chargement, la requête n'a pas rétourner d'informations !!");  
                  Logger.getLogger(Access_data_base.class.getName()).log(Level.SEVERE, null, ex);
                  }     
          } else {
              jTextFieldResultat.setForeground(Color.red);
              jTextFieldResultat.setText("Erreur, le champ ID n'est pas renseigné !!");
                    
              
          }
          
                      
            }             
                                                 
    }//GEN-LAST:event_jButtonCreerActionPerformed

    private void jButtonModifierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifierActionPerformed
        // TODO add your handling code here:
        
       if(this.connexion != null){
          if (!jTextFieldNom.getText().equals("") && !jTextFieldID.getText().equals("") ){
          
              try {
          Statement maRequete = this.connexion.createStatement();
          int modifierTuplesInseres= maRequete.executeUpdate("update clients set nom='"+ jTextFieldNom.getText()  + "'where id=" + jTextFieldID.getText());
	   
                jTextFieldResultat.setForeground(Color.green);
                jTextFieldResultat.setText("Modification réussi");
  
          }catch (SQLException ex) {
                  
                 jTextFieldResultat.setForeground(Color.red);
                jTextFieldResultat.setText("Echec du chargement, la requête n'a pas rétourner d'informations !!");  
                  Logger.getLogger(Access_data_base.class.getName()).log(Level.SEVERE, null, ex);
                  }     
          } else {
              jTextFieldResultat.setForeground(Color.red);
              jTextFieldResultat.setText("Erreur, le champ nom n'est pas renseigné !!");
                     
          }
       
            }               
 
    }//GEN-LAST:event_jButtonModifierActionPerformed

    private void jButtonSupprimerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSupprimerActionPerformed
        // TODO add your handling code here:
        
  if(this.connexion != null){
          if (!jTextFieldID.getText().equals("")){
          
              try {
          Statement maRequete = this.connexion.createStatement();
          int modifierTuplesInseres= maRequete.executeUpdate("delete from clients where id=" + jTextFieldID.getText());
	   
                jTextFieldResultat.setForeground(Color.green);
                jTextFieldResultat.setText("Supressio réussi");
  
          }catch (SQLException ex) {
                  
                 jTextFieldResultat.setForeground(Color.red);
                jTextFieldResultat.setText("Echec de supression, la requête n'a pas rétourner d'informations !!");  
                  Logger.getLogger(Access_data_base.class.getName()).log(Level.SEVERE, null, ex);
                  }     
          } else {
              jTextFieldResultat.setForeground(Color.red);
              jTextFieldResultat.setText("Erreur, le champ ID n'est pas supprimer !!");    
          }       
            }               
    }//GEN-LAST:event_jButtonSupprimerActionPerformed

    /**
         * @param args the command line arguments
         */
      
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Access_data_base.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Access_data_base.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Access_data_base.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Access_data_base.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Access_data_base().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAfficher;
    private javax.swing.JButton jButtonCreer;
    private javax.swing.JButton jButtonCreerTable;
    private javax.swing.JButton jButtonModifier;
    private javax.swing.JButton jButtonSeConnecter;
    private javax.swing.JButton jButtonSupprimer;
    private javax.swing.JButton jButtonSupprimerTable;
    private javax.swing.JButton jButtonTest;
    private javax.swing.JButton jButtonViderTable;
    private javax.swing.JLabel jLabelAdresse;
    private javax.swing.JLabel jLabelDAO;
    private javax.swing.JLabel jLabelEtat;
    private javax.swing.JLabel jLabelEtatCreation;
    private javax.swing.JLabel jLabelEtatSuppression;
    private javax.swing.JLabel jLabelEtatVider;
    private javax.swing.JLabel jLabelID;
    private javax.swing.JLabel jLabelMBPBDD;
    private javax.swing.JLabel jLabelNom;
    private javax.swing.JLabel jLabelNonBDD;
    private javax.swing.JLabel jLabelOutilBDD;
    private javax.swing.JLabel jLabelPort;
    private javax.swing.JLabel jLabelUtilisateurBDD;
    private javax.swing.JPanel jPanelConnexion;
    private javax.swing.JPanel jPanelCrud;
    private javax.swing.JPanel jPanelGestionBDD;
    private javax.swing.JTabbedPane jTabbedPaneAccesBDD;
    private javax.swing.JTextField jTextFieldAdresse;
    private javax.swing.JTextField jTextFieldID;
    private javax.swing.JTextField jTextFieldMBPBDD;
    private javax.swing.JTextField jTextFieldNom;
    private javax.swing.JTextField jTextFieldNomBDD;
    private javax.swing.JTextField jTextFieldNomTableACreer;
    private javax.swing.JTextField jTextFieldNomTableAVider;
    private javax.swing.JTextField jTextFieldPort;
    private javax.swing.JTextField jTextFieldResultat;
    private javax.swing.JTextField jTextFieldTableASupprimer;
    private javax.swing.JTextField jTextFieldUtilisateurBDD;
    // End of variables declaration//GEN-END:variables
}
